import { VUE_APP_API_URL } from "@/config"
export function http(path, method = "POST" , params = {}, data = {}, loading = true) {
	if (loading) {
		uni.showLoading({
			title: "加载中",
			mask: true
		});
	};

	return new Promise((resolve, reject) => {
		try{
			uni.request({
			    url: VUE_APP_API_URL + path, //仅为示例，并非真实接口地址。
			    data,
				params,
				method,
			    header: {
			        'XX-Device-Type': 'wechat' //自定义请求头信息
			    },
			    async success(res) {
			        uni.hideLoading();
			        resolve(res.data);
			    },
				fail(err) {
					uni.hideLoading();
					reject(err);
				},
			});
		}catch(e){
			console.info('错误', e);
			//TODO handle the exception
		}
	});
};

